package com.logansoft.servicegateway.config;

import com.logansoft.servicegateway.filter.GatewayCustomFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liqiye
 * @description gateway filter 的过滤器配置类(为过滤器指定拦截的url)
 * @date 2020/11/2
 */
@Configuration
public class GatewayFilterConfig {

    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r ->
                        r.path("/homework/**")
                                .filters(
                                        f -> f.stripPrefix(0)   // 这个是从前面截取url，例如：/payment/get/1，0是/payment/get/1，1是/get/1
                                                .filters(new GatewayCustomFilter())
                                )
                                .uri("lb://service-homework")
                )
                .build();
    }


}
